﻿using System;
using System.Text;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


using Skyworth.CRM.Common;
using Skyworth.CRM.Service.IBLL;
using Skyworth.CRM.Service.Entity;

namespace Skyworth.CRM.Web.SalesManagement
{
    public partial class CustomerInfo : BasePage
    {
        protected int PolicyId = 0;
        ICustomerBLL custBLL = (ICustomerBLL)IocContainer.Instance.Resolve<ICustomerBLL>();

        protected void Page_Load(object sender, EventArgs e)
        {
            //int.TryParse(Request.QueryString["policyId"], out PolicyId);
            //if (!Page.IsPostBack)
            //{
            //    BindData();
            //}
            BindData();
        }

        private void BindData()
        {
            try
            {
                StringBuilder strWhere = new StringBuilder();
                if (!string.IsNullOrEmpty(this.txtCustCode.Text))
                {
                    strWhere.Append(" and FNumber like '%" + this.txtCustCode.Text + "%'");
                }
                if (!string.IsNullOrEmpty(this.txtCustName.Text))
                {
                    strWhere.Append(" and FName like '%" + this.txtCustName.Text + "%'");
                }
                //if (!string.IsNullOrEmpty(PolicyId.ToString()))
                //{
                //    strWhere.Append(" and not exists(select * from T_Sales_PriceCust as tsp where tsp.PolicyId =" + PolicyId + " and tsp.CustId = T_BasicData_Customer.FItemId) ");
                //}

                this.DataGrid1.Visible = true;
                DataTable dt = custBLL.Query(strWhere.ToString());
                if (dt != null && dt.Rows.Count > 0)
                {
                    this.DataGrid1.DataSource = dt;
                    this.DataGrid1.DataBind();
                }
                else
                {
                    this.DataGrid1.Visible = false;
                }

            }
            catch (Exception exception)
            {
                Logger.Instance.Error(exception);
            }
        }



        protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            DataGrid1.CurrentPageIndex = e.NewPageIndex;
            BindData();

        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }
    }
}